package com.sky.controller.admin;

import com.sky.constant.MessageConstant;
import com.sky.exception.LoginFailedException;
import com.sky.result.Result;
import com.sky.utils.AliOssUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
@Slf4j
@RestController
public class UploadController {
    @Autowired
    private AliOssUtil aliOssUtil;
    @PostMapping("/admin/common/upload")
    public Result<String> upload(@RequestBody MultipartFile file)  {
        log.info("文件上传{}",file);
        String url;
        try {
            url = aliOssUtil.upload(file.getBytes(),file.getOriginalFilename());
        } catch (Exception e) {
            throw new LoginFailedException(MessageConstant.UPLOAD_FAILED);
        }
        return Result.success(url);
    }
}
